<template>
	<el-dialog :visible.sync="visible" title="DCU数据保存" :close-on-click-modal="false" :close-on-press-escape="false">
		<el-form :model="dataForm" ref="dataForm" :rules="dataRule" @keyup.enter.native="confirm()" label-width="120px">
			<el-form-item prop="name" label="DCU数据保存名称">
				<el-input v-model="dataForm.name" placeholder="DCU数据保存名称"></el-input>
			</el-form-item>
		</el-form>
		<template slot="footer">
			<el-button @click="visible = false">{{ $t('cancel') }}</el-button>
			<el-button type="primary" @click="confirm()">{{ $t('confirm') }}</el-button>
		</template>
	</el-dialog>
</template>

<script>
import debounce from 'lodash/debounce'
export default {
	data() {
		return {
			visible: false,
			dataForm: {
				name: ''
			},
			dataObj: {

			}
		}
	},
	computed: {
		dataRule() {
			return {
				name: [
					{ required: true, message: 'DCU数据保存名称', trigger: 'blur' }
				]
			}
		}
	},
	methods: {
		init(obj) {
			this.visible = true
			this.dataObj = obj
		},
		confirm: debounce(function () {
			this.$refs['dataForm'].validate((valid) => {
				if (!valid) {
					return false
				}
				var obj = {
					name: this.dataForm.name,
					...this.dataObj
				}
				this.$http.post('/psc/dcuparameters', obj).then(res => {
					if (res.data.code !== 0) {
						return this.$message.error(res.msg)
					}
					this.$message({
						message: this.$t('prompt.success'),
						type: 'success',
						duration: 500,
						onClose: () => {
							this.visible = false
							this.$emit('refreshDataList')
						}
					})
				})
			})

		})
	}
}
</script>

<style></style>